package com.example.demo.common;

import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;

@Configuration
public class ImageHandle {

    public String getImageAsBase64(String path) throws IOException {
        // 读取图片文件
        File file = new File(path);
        byte[] imageBytes = Files.readAllBytes(file.toPath());

        // 加密
        String encodedString = Base64.getEncoder().encodeToString(imageBytes);
        System.out.println("Encoded String: " + encodedString);

//        // 解码
//        byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
//        String decodedString = new String(decodedBytes);
//        System.out.println("Decoded String: " + decodedString);
        return encodedString;
    }

}
